package com.tenglong.teacher.ui.adapter.viewholder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.cuotibao.zhuoxiao.basics.utils.IpUtils;
import com.cuotibao.zhuoxiao.basics.utils.glide.GlideOptions;
import com.netease.nim.uikit.common.util.sys.TimeUtil;
import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.AnswerInfo;
import com.tenglong.teacher.services.hdx.CreateRequestEntity;
import com.tenglong.teacher.ui.adapter.RelateAnswerAdaper;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;
import com.thinkcool.circletextimageview.CircleTextImageView;

public class RelateViewHolder extends BaseViewHolder<AnswerInfo> {
    private CircleTextImageView headerImage;
    private TextView name;
    private TextView className;
    private TextView howToDo;
    private ImageView image;
    private TextView tip;
    private RelateAnswerAdaper.RelateAnswerListener listener;
    private AnswerInfo info;

    public RelateViewHolder(View itemView) {
        super(itemView);
        initView();
    }

    public RelateViewHolder(View itemView, RelateAnswerAdaper.RelateAnswerListener listener) {
        this(itemView);
        this.listener = listener;
        setListeners();
    }

    private void setListeners() {
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onRelateAnswerListener(info, getAdapterPosition());
                }
            }
        });
    }

    private void initView() {
        headerImage = itemView.findViewById(R.id.headerImage);
        name = itemView.findViewById(R.id.name);
        className = itemView.findViewById(R.id.className);
        howToDo = itemView.findViewById(R.id.howToDo);
        image = itemView.findViewById(R.id.image);
        tip = itemView.findViewById(R.id.tip);
    }

    @Override
    public void setLayoutInfo(AnswerInfo info) {
        this.info = info;
        RequestOptions options = GlideOptions.getGlideRequestOptions().
                error(R.drawable.setting_image_defauft_header).
                placeholder(R.drawable.header_image_loading);
        Glide.with(itemView.getContext())
                .load(IpUtils.getImageUrl(info.stuPhotoUrl))
                .apply(options)
                .into(headerImage);
        name.setText(info.studentname);
        Glide.with(itemView.getContext())
                .load(IpUtils.getImageUrl(info.firstpicmsg))
                .apply(GlideOptions.getGlideRequestOptions().placeholder(R.drawable.answer_default_image)
                        .error(R.drawable.answer_default_image))
                .into(image);
        className.setText(info.classname);
        howToDo.setText(info.firsttextmsg);
        tip.setText(TimeUtil.getFavoriteCollectTime(info.createDate) + "   收藏 " + info.favorite + "人");
    }
}
